Detailed description of DecimalFormat rounding in java,
DecimalFormat is a subclass of NumberFormat used to format decimal numbers. It supports different types of numbers, including INTEGER (123), fixed point (123.4), Scientific notation (1.23E4),
Java. text. DecimalFormat usage details,
Brief
The pattern of DecimalFormat contains the plus and minus child pattern, for example, "#, #0.00; (#, #0.00 )":
/*** Created by Shuai on 2016/7/11. */public class Main {public static void main (String []
This article mainly introduces the Java method to keep the double type two decimal places, please refer to the use of itCopy CodeThe code is as follows:Mport Java.text.DecimalFormat;DecimalFormat df = new DecimalFormat ("##### #0.00");Double D1 = 3.2
Detailed usage of DecimalFormat in Java, javadecimalformat
We often need to format numbers, such as taking 2 decimal places, which is the most common. Java provides the DecimalFormat class to help you format numbers as quickly as possible. The
We often have to format numbers, such as 2 decimal places, which is the most common. Java provides the DecimalFormat class, which helps you to format numbers as quickly as you like. Here is an example:
Importjava.text.DecimalFormat;
Java float retains two decimal places or decimal placesMethod 1: Use Math.Round to calculate the number format that is returned here.float price=89.89;int itemnum=3;float Totalprice=price*itemnum;float num= (float) (Math.Round (totalprice*100)/100);
We often have to format numbers, such as 2 decimal places, which is the most common. Java provides the DecimalFormat class, which helps you to format numbers as quickly as you like. Here is an example:
Importjava.text.DecimalFormat;
Mode one:RoundedDouble F = 111231.5585;Rounding to keep two decimal digits, you can use the Format function of string,The method is as follows:
Copy Code code as follows:
System.out.println (String.Format ("%.2f", X1));
We often need to format numbers, such as taking 2 decimal places, which is the most common. Java provides the decimalformat class to help you format numbers as quickly as possible. The following is an example.
Importjava. text. decimalformat;
Turn from:Java float retains two decimal places or decimal placesMethod 1: Use Math.Round to calculate the number format that is returned here.float price=89.89;int itemnum=3;float totalprice=price*itemnum;float num= (float) (Math.Round (totalprice*1
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.